package com.englisheveryday.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import com.englisheveryday.consants.SQLConstants;
import com.englisheveryday.util.UUIDGenerator;
import com.englisheveryday.vo.FeedBackVO;

/**
 * <pre>
 *    
 * </pre>
 * @author 马永华
 * @date 2012-9-16 上午10:59:54
 * @version 1.1
 */
@SuppressWarnings("unchecked")
public class FeedbackDAO {

   private JdbcTemplate jdbcTemplate;
	
	public FeedbackDAO(JdbcTemplate jdbcTemplate){
		this.jdbcTemplate = jdbcTemplate;
	}
	
	//保存
	public int save(String content){
		return jdbcTemplate.update(SQLConstants.save_feedback, new Object[]{
				UUIDGenerator.generate(),
				content,
				new Date().getTime()
		});
	}
	
	//查询用户反馈
	public List<FeedBackVO> query(int page,int count){
		return jdbcTemplate.query(SQLConstants.query_feedback, new Object[]{page,count},new RowMapper(){
			@Override
			public FeedBackVO mapRow(ResultSet rs, int rowNum) throws SQLException {
				FeedBackVO vo = new FeedBackVO();
				vo.setContent(rs.getString("content"));
				vo.setId(rs.getString("id"));
				vo.setCreatetime(rs.getLong("createtime"));
				return vo;
			}
		});
	}
	
	//删除用户反馈
	public int delete_Feedback(String id){
		return jdbcTemplate.update(SQLConstants.delete_feedback, id);
	}
}

